#include "ll.h"

struct LLNode
{
	int data;
	LLNode * next;
};

LinkedList::LinkedList()
{
	head = 0;
}

int LinkedList::size()
{
	int counter = 0;
	for(LLNode * cursor = head; cursor; cursor = cursor->next)
	{
		counter++;
	}
	return counter;
}

int LinkedList::get(int a_index)
{
	int counter = 0;
	for(LLNode * cursor = head; 
		cursor; cursor = cursor->next)
	{
		if(counter == a_index)
			return cursor->data;
		counter++;
	}
	return -1;
}

void LinkedList::add(int a_value)
{
	LLNode * cursor = head;
	LLNode * newNode = new LLNode;
	newNode->data = a_value;
	newNode->next = 0;
	if(head == 0)
	{
		head = newNode;
	}
	else
	{
		for(; cursor->next; cursor = cursor->next);
		cursor->next = newNode;
	}
}
